package com.seefly.firstmall.util;

import java.util.Properties;

import org.apache.ibatis.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

import com.seefly.firstmall.core.AppConfig;

@Component
public class AppConfigParam implements InitializingBean{
	
	private static final Logger logger = LoggerFactory.getLogger(AppConfigParam.class);
	
	public static final AppConfig appConfig = new AppConfig();

	public static AppConfig getAppconfig() {
		return appConfig;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		
		LogFactory.useLog4JLogging();
		logger.info("AppConfigParam.afterPropertiesSet() begin !"); 
		
		Resource res = new ClassPathResource("/app.properties");
		Properties props = PropertiesLoaderUtils.loadProperties(res);
		appConfig.setWebAppName(props.getProperty("webappname"));
		appConfig.setPageSize(Integer.valueOf(props.getProperty("pagesize")));
		appConfig.setBaseUrl(props.getProperty("baseurl"));
		
		logger.info("AppConfigParam.afterPropertiesSet() finish !");
		
	}
	
}
